package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.server.SetmealServer;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
public class SetmealController {

    @Autowired
    private SetmealServer setmealServer;

    // 分页查询
    @GetMapping("/page")
    public Result<PageResult> getPage(SetmealPageQueryDTO queryDTO) {
        PageResult pageResult = setmealServer.getPage(queryDTO);
        return Result.success(pageResult);
    }

    // 套擦添加
    @PostMapping()
    public Result setmeal(@RequestBody SetmealDTO setmealDTO) {
        setmealServer.addSetmeal(setmealDTO);
        return Result.success("添加套餐成功");
    }

    // 批量删除套餐
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids) {
        setmealServer.deleteBatch(ids);
        return Result.success();
    }


    @GetMapping("/{id}")
    public Result<SetmealVO> getById(@PathVariable Long id) {
        SetmealVO setmealVO = setmealServer.getByIdWithDish(id);
        return Result.success(setmealVO);
    }

    // 修改套餐
    @PutMapping
    public Result update(@RequestBody SetmealDTO setmealDTO) {
        setmealServer.update(setmealDTO);
        return Result.success();
    }

    // 修改状态
    @PostMapping("/status/{status}")
    public Result startOrStop(@PathVariable Integer status, Long id) {
        setmealServer.startOrStop(status, id);
        return Result.success();
    }


}
